#ifndef __STANDARD_H__
#define __STANDARD_H__

/* Include files. */
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>
#include <errno.h>
#include <stdbool.h>
#include <getopt.h>
#include <time.h>
#include <pthread.h>
#include <linux/limits.h>	
#include <net/if.h>


#include <sys/epoll.h>
#include <sys/sysinfo.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/wait.h>

#include <netinet/in.h>
#include <arpa/inet.h>

#include "lua.h" 
#include "lualib.h" 
#include "lauxlib.h" 

/* Macro constant definitions. */

//#define TEST_VERSION

#ifdef U_LOOP
#include <libubus.h>
#include "libubox/list.h"
#include <libubox/uloop.h>
#include <json-c/json.h>
#include <fcgiapp.h>
#include <libubox/blobmsg_json.h>
#define _unused __attribute__((unused))
#else
#include <ev.h>
#endif

/* Macro API definitions. */

#ifndef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
#define ALIGN(x, n) ((x + (n - 1)) & ~(n - 1))

#define NIPQUAD(addr) \
	((unsigned char *)&addr)[3], \
	((unsigned char *)&addr)[2], \
	((unsigned char *)&addr)[1], \
	((unsigned char *)&addr)[0]
#define NIPQUAD_FMT "%u.%u.%u.%u"

#define TCP_NORMAL_ERR(e)		((e) == EINTR || (e) == EAGAIN || (e) == EWOULDBLOCK)
#define TCP_NOT_ERROR(errno) 	((errno) == 0 || (errno) == EAGAIN)

#define SOCKOPT_NOBLOCK(socket, noblock) do{\
	int val = (noblock);\
	ioctl((socket), FIONBIO, (void *)&val);\
}while(0)

/* Type definitions. */
#ifndef int8
	typedef char int8;
#endif
#ifndef u8
	typedef unsigned char u8;
#endif
#ifndef int16
	typedef short int16;
#endif
#ifndef u16
	typedef unsigned short u16;
#endif
#ifndef int32
	typedef int int32;
#endif
#ifndef	u32
	typedef unsigned int u32;
#endif
#ifndef int64
	typedef long long int64;
#endif
#ifndef u64
	typedef unsigned long long u64;
#endif

typedef enum 
{
	e_OK = 0,
	e_CONTINUE,
	e_ERROR,
}e_stat;

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif 

/* External variable declarations. */

/* External function declarations. */

#endif
